VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "msflxgrd.ocx"
Begin VB.Form Form3 
   BackColor       =   &H80000003&
   Caption         =   "Form3"
   ClientHeight    =   4980
   ClientLeft      =   2265
   ClientTop       =   2220
   ClientWidth     =   10080
   LinkTopic       =   "Form3"
   ScaleHeight     =   4980
   ScaleWidth      =   10080
   Begin VB.CommandButton Command3 
      BackColor       =   &H80000003&
      Caption         =   "Clear"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   222
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   615
      Left            =   8640
      MaskColor       =   &H00800000&
      Style           =   1  'Graphical
      TabIndex        =   5
      Top             =   480
      Width           =   1335
   End
   Begin MSFlexGridLib.MSFlexGrid Grid2 
      Height          =   3615
      Left            =   360
      TabIndex        =   4
      Top             =   1200
      Width           =   9615
      _ExtentX        =   16960
      _ExtentY        =   6376
      _Version        =   393216
      Rows            =   10
      Cols            =   10
      BackColor       =   16777215
      BackColorFixed  =   -2147483645
      BackColorBkg    =   16777215
      MergeCells      =   1
      FormatString    =   ""
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   222
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin VB.CommandButton Command2 
      BackColor       =   &H80000003&
      Caption         =   "Back"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   222
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   615
      Left            =   7200
      MaskColor       =   &H00800000&
      Style           =   1  'Graphical
      TabIndex        =   2
      Top             =   480
      Width           =   1335
   End
   Begin VB.CommandButton Command1 
      BackColor       =   &H80000003&
      Caption         =   "Search"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   222
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   615
      Left            =   5760
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   480
      Width           =   1335
   End
   Begin VB.TextBox Txt1 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   222
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   615
      Left            =   3120
      TabIndex        =   0
      Top             =   480
      Width           =   2535
   End
   Begin VB.Label Label1 
      BackColor       =   &H80000003&
      Caption         =   "Please Key Game Name"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   222
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00400000&
      Height          =   495
      Left            =   360
      TabIndex        =   3
      Top             =   600
      Width           =   2775
   End
End
Attribute VB_Name = "Form3"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public adoCn As New ADODB.Connection  'connection ติดต่อกับฐานข้อมูล
Public adoRs As New ADODB.Recordset    'เก็บชุดของข้อมูลที่ได้จากการประมวลผลคำสั่ง SQL (Select *from tb-name)
Public Sql As String
Public Sub DBCnn()  'ฟังก์ชั่นติดต่อฐานข้อมูล
    With adoCn
        .Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\m5.mdb;Persist Security Info=False"
    End With
End Sub
Private Sub Command1_Click()
Dim serchString As String
Dim i As String
Dim Sql As String
Dim Row As Integer
serchString = Me.Txt1.Text
'Sql = "select * from student5 where stdf like '%" & serchString & "%'"
Sql = "select * from student5 where stdf like " & "'" & Txt1.Text & "'"
           Set adoRs = Nothing   'เคลียร์เรคคอร์ดเซ็ต
           adoRs.Open Sql, adoCn, adOpenKeyset, adLockReadOnly    'ชุดของการประมวลผลคำสั่งจำไปใช้งาน
           If adoRs.EOF Then     'ตรวจสอบว่าพบข้อมูลหรือไม่ถ้าไม่พบทำบรรทัดถัดไป
                MsgBox "ไม่พบข้อมูลที่ต้องการค้นหา กรุณาพิมพ์ข้อมูลใหม่"
                Me.MousePointer = 0
                Exit Sub   'ออกจาก Sub Program
            Else
            Gridshow1
            adoRs.Close
            End If
Me.MousePointer = 0  'คืออะไร
End Sub
Private Sub Command2_Click()
Form3.Hide
Form2.Show
End Sub

Private Sub Command3_Click()
Dim serchString As String
Txt1 = ""
'reload
End Sub

Private Sub Form_Load()
Call DBCnn
End Sub

Private Sub Txt1_KeyPress(KeyAscii As Integer)
If (KeyAscii = 13) Then
   Command1.SetFocus
End If
End Sub
Sub Gridshow1()
Dim serchString As String
Dim i As String
Dim Sql As String
Dim Row As Integer
                i = 1
               Grid2.Rows = 2  'เริ่มต้นให้กริดมีค่าเท่ากับ 2 แถว
                Row = Me.Grid2.Rows - 1   'หาแถวเริ่มต้นที่ต้องการแสดงข้อมูล
                    Do Until adoRs.EOF   'ตรวจสอบว่าเป็น End of File หรือไม่
                    With Me.Grid2
                        .ColWidth(0) = 350
                        .ColWidth(1) = 900
                        .ColWidth(2) = 1700
                        .ColWidth(3) = 1000
                        .ColWidth(4) = 1000
                        .ColWidth(5) = 800
                        .ColWidth(6) = 1300
                        .ColWidth(7) = 550
                        .ColWidth(8) = 1300
                        .ColWidth(9) = 550
                        .ColAlignment(0) = 9
                        .ColAlignment(1) = 9
                        .TextMatrix(0, 0) = "No"
                        .TextMatrix(0, 1) = "ID-Code"
                        .TextMatrix(0, 2) = "Game Name"
                        .TextMatrix(0, 3) = "Disc Zone"
                        .TextMatrix(0, 4) = "Language"
                        .TextMatrix(0, 5) = "In Stock"
                        .TextMatrix(0, 6) = "Game Console"
                        .TextMatrix(0, 7) = "Rate"
                        .TextMatrix(0, 8) = "Made by"
                        .TextMatrix(0, 9) = "Price"
                        .TextMatrix(Row, 0) = i
                        .TextMatrix(Row, 1) = adoRs("stdid") & ""
                        .TextMatrix(Row, 2) = adoRs("stdf") & ""
                        .TextMatrix(Row, 3) = adoRs("stdname") & ""
                        .TextMatrix(Row, 4) = adoRs!stdsur & ""
                        .TextMatrix(Row, 5) = adoRs!stdaddress & ""
                        .TextMatrix(Row, 6) = adoRs!stdamp & ""
                        .TextMatrix(Row, 7) = adoRs!stdpro & ""
                        .TextMatrix(Row, 8) = adoRs!stdtel & ""
                        .TextMatrix(Row, 9) = adoRs!stdemail & ""
                        i = i + 1
                        .Rows = .Rows + 1   'เพิ่มแถวขึ้นหนึ่งแถว
                        Row = .Rows - 1   'หาแถวที่จะเพิ่มข้อมูลในแถวถัดไป
                    End With
                         adoRs.MoveNext  'เลื่อนเรคคอร์ดถัดไป
                   Loop
End Sub
Sub reload()
With Grid2
Txt1 = .TextMatrix(.Row, 1)
If adoCn.State = 1 Then adoRs.Close
adoCn.Open "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\m5.mdb"
Sql = "select * from student5  where  stdid='" & Txt1 & "'"
If adoRs.RecordCount > 0 Then
.ColWidth(0) = 350
                        .ColWidth(1) = 900
                        .ColWidth(2) = 1700
                        .ColWidth(3) = 1000
                        .ColWidth(4) = 1000
                        .ColWidth(5) = 800
                        .ColWidth(6) = 1300
                        .ColWidth(7) = 550
                        .ColWidth(8) = 1300
                        .ColWidth(9) = 550
                        .ColAlignment(0) = 9
                        .ColAlignment(1) = 9
                        .TextMatrix(0, 0) = "No"
                        .TextMatrix(0, 1) = "ID-Code"
                        .TextMatrix(0, 2) = "Game Name"
                        .TextMatrix(0, 3) = "Disc Zone"
                        .TextMatrix(0, 4) = "Language"
                        .TextMatrix(0, 5) = "In Stock"
                        .TextMatrix(0, 6) = "Game Console"
                        .TextMatrix(0, 7) = "Rate"
                        .TextMatrix(0, 8) = "Made by"
                        .TextMatrix(0, 9) = "Price"
End If
End With
End Sub
Private Sub Grid2_Click()
   reload
End Sub
